from django.db import models
from login.models import User


# Create your models here.

class Hotel(models.Model):
    """宾馆模型类"""

    owner = models.OneToOneField(User, on_delete=models.CASCADE, related_name='user_hotel', verbose_name='所有者')
    name = models.CharField(verbose_name='宾馆名', max_length=100)
    address = models.CharField(verbose_name='宾馆地址', max_length=255)

    class Meta:
        db_table = 'hotel'
        verbose_name = verbose_name_plural = '宾馆'

    def __str__(self):
        return self.name


class Room(models.Model):
    """房间模型类"""

    hotel = models.ForeignKey(Hotel, on_delete=models.CASCADE, related_name='hotel_rooms', verbose_name='所在宾馆')
    capacity = models.IntegerField(verbose_name='房间容量')
    price = models.DecimalField(max_digits=7, decimal_places=2, verbose_name='每日价格')

    class Meta:
        db_table = 'room'
        verbose_name = verbose_name_plural = '房间'

    def __str__(self):
        return 'Room ' + str(self.id)


class Booking(models.Model):
    """订单模型类"""

    hotel = models.ForeignKey(Hotel, on_delete=models.CASCADE, related_name='hotel_bookings', verbose_name='宾馆')
    room = models.ForeignKey(Room, on_delete=models.CASCADE, related_name='room_bookings', verbose_name='房间')
    guest = models.ForeignKey(User, on_delete=models.CASCADE, related_name='user_bookings', verbose_name='顾客')
    date_from = models.DateField(verbose_name='入住日期')
    date_to = models.DateField(verbose_name='退房日期')

    class Meta:
        db_table = 'booking'
        verbose_name = verbose_name_plural = '房间订单'

    def __str__(self):
        return 'Booking ' + str(self.id)
